import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/setcookie")
public class SetCookieServlet extends HelloServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //通过get将一个自定义的cookie返回到浏览器
        resp.setHeader("charset","utf8");
        Cookie cookie1 = new Cookie("data","123456");
        Cookie cookie2 = new Cookie("time","111111");
        Cookie cookie3 = new Cookie("password","666666");
        resp.addCookie(cookie1);
        resp.addCookie(cookie2);
        resp.addCookie(cookie3);
        resp.getWriter().write("setCookie ok");
    }
}
